/**
 * <p><b>Title:</b> AssertLevelFilter.java </p>
 *
 * @Package com.wondertek.oes.charge.service.manager.rule.filter
 */
package com.wondertek.poms.core.filter.impl;

import com.wondertek.poms.core.filter.BaseRuleFilter;
import com.wondertek.poms.core.filter.RuleFilterChain;
import org.apache.commons.lang3.StringUtils;

import com.wondertek.poms.dao.po.Content;
import com.wondertek.poms.dao.po.DefaultPrdSal;
import com.wondertek.poms.dao.po.IRulePo;
import com.wondertek.poms.dao.po.PrdInfoRule;


/**
 * <p><b>AssertLevelFilter Description:</b> 内容评级过滤器</p>
 *
 * @author douzi
 * <b>DATE</b> 2019年8月30日 下午3:09:13
 */
public class AssertLevelFilter extends BaseRuleFilter {

    @Override
    public void doFilter(IRulePo rule, Content c, RuleFilterChain chain) {
        if (rule instanceof PrdInfoRule) {
            PrdInfoRule r = (PrdInfoRule) rule;
            process(r.getPrdRuleId(), r.getContentLevel(), c.getContentLevel(), chain);
        } else if (rule instanceof DefaultPrdSal) {
			DefaultPrdSal r = (DefaultPrdSal) rule;
			this.baseFilter(r.getId(), r.getContentLevel(), c.getContentLevel(), chain, "内容评级-ContentLevel");
		}
        chain.doFilter(rule, c, chain);
    }

    public void process(Long id, String ruleStr, String voStr, RuleFilterChain chain) {
    	if (chain.isFlag() && StringUtils.isNotBlank(ruleStr)) {
    		chain.setFlag(Boolean.FALSE);
    		
    		if (StringUtils.isBlank(voStr)) {
    			if ("9".equals(ruleStr)) {
                    chain.setFlag(Boolean.TRUE);
                }
    		} else {
    			if (StringUtils.contains(ruleStr, voStr)) {
                    chain.setFlag(Boolean.TRUE);
                }
    		}
    		log(id, chain, "内容评级-ContentLevel", ruleStr, voStr);
        }
    }

}
